<?php include("includes/session.php"); ?>
<?php include("includes/connect_db.php"); ?>
<?php include("includes/header.php"); ?>
<?php include("notif.php"); ?>

<?php
	$id_host = $_GET['id'];

	$sql_lihat_host = "SELECT * FROM tb_host WHERE id_host = '$id_host'";
	$query_lihat_host = mysql_query($sql_lihat_host);
	$lihat_host = mysql_fetch_array($query_lihat_host)
?>

<style>
	div{
		font-family: 'SEGOE UI';
	}

	input{
		width: 400px;
	}
</style>

<div class="span9">  
    <h3>SMS</h3>                      
    <ul class="breadcrumb well">
    	<li><a href="kontak.php">Koneksi</a> <span class="divider">/</span></li>
        <li class="active">Ubah</li>                
    </ul>    
    <div class="alert alert-info">
		Ubah Koneksi
    </div>
    
	<form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    	<div>
			<div class="control-group">
				<label class="control-label">Nama Host</label>
				<div class="controls">
					<input type="hidden" name="id_host" value="<?php echo $lihat_host['id_host']; ?>">
					<input placeholder="Masukkan Nama Host" type="text" name="nama_host" value="<?php echo $lihat_host['nama_host']; ?>">
					<i class="icon-ok-circle" style="opacity: 0.5"></i>
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">Alamat IP</label>
				<div class="controls">
					<input placeholder="Masukkan Alamat IP Host" type="text" name="host" value="<?php echo $lihat_host['host']; ?>">
					<i class="icon-ok-circle" style="opacity: 0.5"></i>
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">Username Host</label>
				<div class="controls">
					<input placeholder="Masukkan Username Host" type="text" name="username" value="<?php echo $lihat_host['username']; ?>">
					<i class="icon-ok-circle" style="opacity: 0.5"></i>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">Password</label>
				<div class="controls">
					<input placeholder="Masukkan Password Host" type="password" name="pass" value="<?php echo $lihat_host['password']; ?>">
					<i class="icon-ok-circle" style="opacity: 0.5"></i>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">Database</label>
				<div class="controls">
					<input placeholder="Masukkan Database Yang Digunakan" type="text" name="database" value="<?php echo $lihat_host['db']; ?>">
					<i class="icon-ok-circle" style="opacity: 0.5"></i>
				</div>
			</div>
		</div>
		<div>
			<div class="span12">
				<ul class="breadcrumb well">
					<button type="submit" style="width: 80px;" class="btn btn-info" name="simpan">Simpan</button>
					<button type="submit" style="width: 80px;" class="btn btn-danger" name="batal">Batal</button>
				</ul>
			</div>
		</div>
	</form>
</div>

<?php
	if(isset($_POST['simpan'])){
		$id_host = $_POST['id_host'];
		$nama_host = $_POST['nama_host'];
		$host = $_POST['host'];
		$username = $_POST['username'];
		$pass = $_POST['pass'];
		$database = $_POST['database'];

		if (empty($nama_host) or empty($host) or empty($username) or empty($database)){
            echo "<SCRIPT> alert('Isi Data Terlebih dahulu');</SCRIPT>";
        } else{
    		$sql_input_koneksi = "UPDATE tb_host 
    							  SET nama_host='$nama_host', host='$host', username='$username', password='$pass', db='$database' 
    							  WHERE id_host = '$id_host'";

			$query_input_koneksi = mysql_query($sql_input_koneksi) or die(mysql_error());

			if ($query_input_koneksi) {
				echo "<SCRIPT> alert('Data Disimpan'); location.href='host.php';</SCRIPT>";
			} else {
				echo "<SCRIPT> alert('Data Gagal Disimpan');</SCRIPT>";
			}
	  	}
	} elseif (isset($_POST['batal'])) {
		echo "<SCRIPT> location.href='host.php';</SCRIPT>";
	}
?>

<?php include("includes/footer.php"); ?>

<script type="text/javascript">
	
</script>